const _completeDeepClone = (target, map = new Map()) => {
  // map 存的是 target, clone映射，只有会产生自身引用的变量需要记录
  // null
  if (target === null) return null;

  // 基本数据类型
  if (typeof target !== "object") return target;

  // 函数
  if (typeof target === "function") {
    return function () {
      return target.apply(this, arguments);
    };
  }

  // 后面都是引用类型，先进行循环引用检查
  if (map.has(target)) return map.get(target);

  // 特殊对象类型，但能自实现深拷贝
  if (target instanceof Date) return new Date(target);
  if (target instanceof RegExp) return new RegExp(target);

  // Map
  if (target instanceof Map) {
    const clone = new Map();
    target.forEach((val, key) => {
      clone.set(_completeDeepClone(key, map), _completeDeepClone(val, map));
    });
    map.set(target, clone);
    return clone;
  }

  // Set
  if (target instanceof Set) {
    const clone = new Set();
    target.forEach((val) => {
      clone.add(_completeDeepClone(val, map));
    });
    map.set(target, clone);
    return clone;
  }

  // 数组和对象无法自实现深拷贝
  const clone = Array.isArray(target) ? [] : {};
  map.set(target, clone);
  for (const key in target) {
    if (target.hasOwnProperty(key))
      clone[key] = _completeDeepClone(target[key], map);
  }
  return clone;
};
